#region Summary 

// 
// Owner : JackieHan 
// 
// Solution : WebControl 
// 
// Project : WebControls 
// 
// File : CreditCarControl.cs 
// 
// CopyRight : Copyright © 2009-2010 XunGu Corporation, All Rights Reserved 
// 
// Summary : 信用卡展示控件 
// 
// History : 
//			2010-04-30 16:27:44	    Create 
// 

#endregion

#region Using 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Web.UI;

#endregion

namespace JackieHan.WebControls
{
    /// <summary> 
    /// 信用卡展示控件 
    /// </summary>
    [DefaultProperty("CardholderNameText")] //默认标记
    //指定当从 Microsoft Visual Studio 等工具中的工具箱拖动自定义控件时为它生成的默认标记
    [ToolboxData("<{0}:CreditCardControl PaymentMethodText=\"信用卡类型\" CreditCardNoText=\"信用卡卡号\""
        +"CardholderNameText=\"信用卡持有者姓名\" SubmitButtonText=\"提交\" runat=\"server\" />")]
    public class CreditCardControl:Control
    {
        private const string PAYMENT_METHOD_TEXT = "信用卡类型";
        private const string CREDIT_CARD_NO_TEXT = "信用卡卡号";
        private const string CARDHOLDER_NAME_TEXT = "信用卡持有者姓名";
        private const string EXPIRATION_DATE_TEXT = "最后使用时间";
        private const string SUBMIT_BUTTON_TEXT = "提交";

        [Browsable(true)]
        [Description("获取或设置信用卡类型")]
        [DefaultValue("信用卡类型")]
        [Category("Appearance")]
        public string PaymentMethodText
        {
            get {
                return ViewState["PaymentMethodText"] != null
                           ? (string) ViewState["PaymentMethodText"]
                           : PAYMENT_METHOD_TEXT; }
            set { ViewState["PaymentMethodText"] = value; }
        }

        [Browsable(true)]
        [Description("获取或设置信用卡卡号")]
        [DefaultValue("信用卡卡号")]
        [Category("Appearance")]
        public string CreditCardNoText
        {
            get { return ViewState["CreditCardNoText"] != null 
                                ? (string) ViewState["CreditCardNoText"] 
                                : CREDIT_CARD_NO_TEXT; }
            set { ViewState["CreditCardNoText"] = value; }
        }

        [Browsable(true)]
        [Description("获取或设置信用卡持有者姓名")]
        [DefaultValue("信用卡持有者姓名")]
        [Category("Appearance")]
        public string CardholderNameText
        {
            get
            {
                return ViewState["CardholderNameText"] != null
                              ? (string)ViewState["CardholderNameText"]
                              : CARDHOLDER_NAME_TEXT;
            }
            set { ViewState["CardholderNameText"] = value; }
        }

        [Browsable(true)]
        [Description("获取或设置最后使用时间")]
        [DefaultValue("最后使用时间")]
        [Category("Appearance")]
        public string ExpirationDateText
        {
            get
            {
                return ViewState["ExpirationDateText"] != null
                             ? (string)ViewState["ExpirationDateText"]
                             : EXPIRATION_DATE_TEXT;
            }
            set { ViewState["ExpirationDateText"] = value; }
        }

        [Browsable(true)]
        [Description("获取或设置按钮标签")]
        [DefaultValue("提交")]
        [Category("Appearance")]
        public string SubmitButtonText
        {
            get
            {
                return ViewState["SubmitButtonText"] != null
                           ? (string)ViewState["SubmitButtonText"]
                           : SUBMIT_BUTTON_TEXT;
            }
            set { ViewState["SubmitButtonText"] = value; }
        }

        protected override void Render(HtmlTextWriter writer)
        {
            writer.Write("<table style='width:287px;height:124px;border-width:0;'>");
            writer.Write("<tr>");
            writer.Write("<td><strong>"+PaymentMethodText+"</strong></td>");
            writer.Write("<td>");
            writer.Write("<select name='PaymentMethod' id='PaymentMethod' style='width:100%;'>");
            writer.Write("<option value='0'>Visa</option>");
            writer.Write("<option value='1'>MasterCard</option>");
            writer.Write("</select>");
            writer.Write("</td>");
            writer.Write("</tr>");
            writer.Write("<tr>");
            writer.Write("<td><strong>"+CreditCardNoText+"</strong></td>");
            writer.Write("<td><input name='CreditCardNo' id='CreditCardNo' type='text' /></td>");
            writer.Write("</tr>");
            writer.Write("<tr>");
            writer.Write("<td><strong>"+CardholderNameText+"</strong></td>");
            writer.Write("<td><input name='CardholderName' id='CardholderName' type='text' /></td>");
            writer.Write("</tr>");
            writer.Write("<tr>");
            writer.Write("<td><strong>"+ExpirationDateText+"</strong></td>");
            writer.Write("<td>");
            writer.Write("<select name='Month' id='Month'>");
            for (int day = 1; day < 13; day++)
            {
                if (day < 10)
                    writer.Write("<option value='" + day.ToString() + "'>" + "0" + day.ToString() + "</option>");
                else
                    writer.Write("<option value='" + day.ToString() + "'>" + day.ToString() + "</option>");
            }
            writer.Write("</select>");
            writer.Write("&nbsp");
            writer.Write("<select name='Year' id='Year'>");
            for (int year = 2005; year < 2015; year++)
            {
                writer.Write("<option value='" + year.ToString() + "'>" + year.ToString() + "</option>");
            }
            writer.Write("</select>");
            writer.Write("</td>");
            writer.Write("</tr>");
            writer.Write("<tr>");
            writer.Write("<td align='center' colspan='2'>");
            writer.Write("<input type='submit' value='"+SubmitButtonText+"' />");
            writer.Write("</td>");
            writer.Write("</tr>");
            writer.Write("</table>");
            base.Render(writer);
        }
    }
}
